package com.example.demo.database.mywait;

import java.util.concurrent.TimeUnit;

public class Wait {
	public static void main(String[] args) throws InterruptedException {
		for (int i = 0; i < 20; i++) {
			SonThread sonThread = new SonThread();
			sonThread.start();
			synchronized (sonThread) {
				System.err.println(Thread.currentThread().getName());
				sonThread.notifyAll();
			}
		}
		TimeUnit.SECONDS.sleep(2);
		System.out.println("主线程名称：["+Thread.currentThread().getName()+"]");
	}
	
	static class SonThread extends Thread{
		@Override
		public void run() {
			 synchronized (this) {
				 try {
						System.out.println(Thread.currentThread().getName()+"等待");
						Thread.currentThread().wait();
						System.out.println(Thread.currentThread().getName()+"唤醒");
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			 }
			
		}
	}
}
